#include "hash.h"
#include "Water.h"

using namespace std;
using namespace glm;

void render_water(string sim_file, int width, int height, Scene *scene) {
    ifstream file;
    int frames, particles, i;
    float radius, x, y, z;
    vec3 min, max, cur;
    HashTable *hash;
    HNode head, *temp;
    Sphere *p;

    file.open(sim_file.c_str());
    file >> frames;
    file >> particles;
    file >> radius;

    cout << frames << endl << particles << endl << radius << endl;


    head.next = new HNode();
    hash = new HashTable(particles, radius);
    file >> x >> y >> z;
    min = max = vec3(x, y, z);
    p = new Sphere();
    p->center = vec3(x, y, z);
    p->radius = 0.04823f;
    p->id = 0;
    head.next->p = p;
    temp = head.next;
    hash->insert(p);

    for (i = 1; i < particles; i++) {
        file >> x >> y >> z;
        if (min.x > x)
            min.x = x;
        if (min.y > y)
            min.y = y;
        if (min.z > z)
            min.z = z;
        if (max.x < x)
            max.x = x;
        if (max.y < y)
            max.y = y;
        if (max.z < z)
            max.z = z;

        temp->next = new HNode();
        cur = vec3(x, y, z);
        p = new Sphere();
        p->center = cur;
        p->radius = 0.04823f;
        p->id = i;
        temp->next->p = p;
        hash->insert(p);
        temp = temp->next;
    }

    print_list(head.next);
}
